<template>
	<view class="content">
		<view class="block news-block">
			<template v-if="list.length>0">
				<view class="news-item" v-for="(item) in list" :key="item.id"
					@click="navigate('/page_other/article/detail?id='+item.id)">
					<view class="news">
						<image :src="item.ima_url" mode="aspectFill" class="news-icon"></image>
						<view class="news-content">
							<view class="news-title">{{item.title}}</view>
							<view class="desc">{{item.abstract}}</view>
							<view class="time">发布时间：{{item.crt_time}}</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else-if="list.length>0&&!more" style="text-align: center;">没有更多了哦</view>
			<view v-else style="text-align: center;">暂无数据</view>
		</view>

	</view>
</template>

<script>
	import {
		getNewsList as getNewsListApi
	} from '@/api/notice.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				imageUrl: '',
				list: [],
				page: 1,
				limit: 10,
				more: true
			}
		},
		methods: {
			refresh() {
				this.page = 1
				this.more = true
				this.getList(true);
			},
			async getList(refresh = false) {
				if (this.more) {
					let config = {
						type: 1,
						page: this.page,
						limit: this.limit
					}
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					let res = await getNewsListApi(config)
					let list = res.list ?? [];
					this.list = refresh ? list : [...this.list, ...list],
						this.total = res.count
					this.more = isMore(this.page, this.limit, this.total)
				}
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
		},
		onLoad() {
			this.imageUrl = this.globalConfig.imageUrl;
			this.getList(true);
		},
		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #fafafa;
	}

	.content {
		width: 100%;
		padding: 30rpx;

		.block {
			width: 100%;
			//margin-bottom: 50rpx;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 40rpx 0 30rpx 0;

				.t-left {
					display: flex;
					align-items: center;

					.pre-icon {
						width: 15rpx;
						height: 37rpx;
						background-color: #ff7626;
						border-radius: 16rpx;
						margin-right: 10rpx;
					}

					.name {
						font-weight: bold;
					}
				}

				.more {
					font-size: 30rpx;
					color: #999;
				}
			}

		}

		.block.swiper-block {
			height: 280rpx;
			box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
			border-radius: 20rpx;
		}

		.block.apply-block {
			.item-block {
				width: 100%;
				height: 320rpx;
				background-color: #fff;
				box-shadow: 0px 0px 4px #ccc;
				border-radius: 10rpx;
				margin: 30rpx auto 10rpx auto;
				padding: 25rpx;

				.top-title {
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1px solid #f6f6f6;
					padding-bottom: 25rpx;

					.apply-title {
						font-weight: bold;
					}

					.btn {
						width: 160rpx;
						height: 55rpx;
						line-height: 55rpx;
						border-radius: 50rpx;
						text-align: center;
						color: #fff;
						background-color: #ff7626;
						font-size: 28rpx;
					}
				}

				.desc-block {
					display: flex;
					flex-direction: column;

					.desc {
						display: flex;
						align-items: center;
						margin: 20rpx 0 0rpx 0;

						.desc-icon {
							width: 30rpx;
							margin-right: 12rpx;
						}

						.desc-text {
							font-size: 30rpx;

							.label {
								color: #999;
							}
						}
					}
				}
			}
		}

		.block.video-block {
			width: 100%;
			margin-top: 20rpx;

			.video-item {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.video {
					width: calc(100% / 2 - 10rpx);
					margin-bottom: 20rpx;
					display: flex;
					flex-direction: column;

					.video-icon {
						width: 100%;
						height: 220rpx;
					}

					.name {
						font-size: 30rpx;
						background-color: #fff;
						padding: 10rpx;
					}
				}

			}

			.video-item:nth-child(2n) {
				margin-right: 0rpx;
			}
		}

		.block.news-block {
			.title {
				margin: 20rpx 0 30rpx 0;
			}

			.news {
				display: flex;
				background-color: #fff;
				padding: 25rpx;
				box-shadow: 0px 0px 4px #ccc;
				border-radius: 10rpx;
				margin-bottom: 30rpx;
				height: 230rpx;

				.news-icon {
					width: 180rpx;
					height: 180rpx;
					border-radius: 16rpx;
					margin-right: 20rpx;
				}

				.news-content {
					width: calc(100% - 200rpx);
					display: flex;
					flex-direction: column;

					.news-title {
						font-weight: bold;
						margin-bottom: 10rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						word-break: break-all;
					}

					.desc {
						color: #999;
						font-size: 28rpx;
						margin-bottom: 10rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						word-break: break-all;
						height: 80rpx;
					}

					.time {
						color: #999;
						font-size: 28rpx;
					}
				}
			}
		}
	}
</style>